<template>
  <span>
    <div class="spinner">
      <div class="spinner-bounce1" :style="bounceStyle"></div>
      <div class="spinner-bounce2" :style="bounceStyle"></div>
      <div class="spinner-bounce3" :style="bounceStyle"></div>
    </div>
  </span>
</template>

<script>
export default {
  name: 'mt-spinner',
  computed: {
    spinnerSize() {
      if (!this.size) {
        return '12px';
      } else if (/^[.\d]+$/g.test(this.size)) {
        return `${this.size}px`;
      }
      return this.size;
    },
    bounceStyle() {
      return {
        width: this.spinnerSize,
        height: this.spinnerSize,
        backgroundColor: this.color,
      };
    },
  },
  props: {
    size: {
      // type: Number,
      default: 6,
    },
    color: {
      type: String,
      default: '#70c1b3',
    },
  },
};
</script>
<style lang="scss" scoped>
.spinner {
  display: inline-block;
  .spinner-bounce1,
  .spinner-bounce2,
  .spinner-bounce3 {
    vertical-align: middle;
    border-radius: 50%;
    display: inline-block;
    animation: spinner 1.4s infinite ease-in-out both;
  }
  .spinner-bounce1 {
    animation-delay: -0.32s;
  }
  .spinner-bounce2 {
    animation-delay: -0.16s;
  }
  @keyframes spinner {
    0%,
    80%,
    100% {
      transform: scale(0);
    }
    40% {
      transform: scale(1);
    }
  }
}
</style>

